<template>
  <div class="app-container">
    <pro-table
      ref="pageBox"
      title="收发记录"
      :request="getList"
      :columns="columns"
      :search="searchObj"
      @selectionChange="handleSelectionChange"
    >
      <template #date="{ row }">
        {{ row.createTime | parseTime }}
      </template>
    </pro-table>
  </div>
</template>
<script>
// import ImportUser from './components/ImportUser'
// import AddEdit from './components/AddEdit'
export default {
  name: 'Contacts',
  // components: { AddEdit, ImportUser },
  data() {
    return {
      showImport: false,
      showPageModal: false,
      selectedRow: {},
      isAddEdit: false,
      showAddEdit: false,
      selectedArr: [],
      columns: [
        // { type: 'expand', tdSlot: 'expand' },
        // { type: 'selection' },
        {
          label: '应用',
          prop: 'applicationId',
        },
        {
          label: '任务名称',
          prop: 'task',
        },
        {
          label: '通道',
          prop: 'channel',
        },
        {
          label: '方向',
          prop: 'direction',
        },
        {
          label: '号码',
          prop: 'number',
        },
        {
          label: '状态',
          prop: 'status',
        },
        {
          label: '解析次数',
          prop: 'parseCount',
        },
        {
          label: '创建时间',
          tdSlot: 'date',
          align: 'center',
          width: 160,
        },

        // {
        //   label: '操作',
        //   tdSlot: 'operate',
        //   width: 120,
        //   align: 'center',
        //   fixed: 'right',
        // },
      ],
      searchObj: {
        inputWidth: '200px',
        fields: [
          {
            type: 'select',
            label: '',
            name: 'applicationId',
            placeholder: '应用',
            options: [],
          },
          {
            type: 'select',
            label: '',
            name: 'channel',
            placeholder: '通道',
            options: [],
          },
          {
            type: 'select',
            label: '',
            name: 'direction',
            placeholder: '方向',
            options: [
              {
                value: 'IN',
                name: '收到',
              },
              {
                value: 'OUT',
                name: '发出',
              },
            ],
          },
          {
            type: 'select',
            label: '',
            name: 'status',
            placeholder: '状态',
            options: [],
          },
          {
            type: 'text',
            label: '',
            name: 'keyword',
            placeholder: '号码、内容',
          },
        ],
      },
    }
  },

  methods: {
    async getList(params) {
      const { code, data } = await new Promise(resolve => {
        setTimeout(() => {
          resolve({
            code: 200,
            data: {
              list: [
                {
                  applicationId: '148946854485172173',
                  billed: false,
                  channel: 'PRIV',
                  channelId: 'SIMULATOR',
                  content:
                    '{"applicationId":148946854485172173,"channelId":"SIMULATOR","channelType":"PRIV","contributionId":"c9122d22-f915-464c-9022-3b942b0774ee","from":"+8616388942203","id":187573333624095394,"msgId":"4f254398-12fa-67a3-e964-2226b1cd31f7","payload":{"text":"热热的三个人"},"to":"106000078673950","type":"TEXT"}',
                  createTime: '2022-01-30T14:33:20.000+0000',
                  direction: 'IN',
                  enterpriseId: '141598637888113837',
                  id: '187573333624095394',
                  msgId: '4f254398-12fa-67a3-e964-2226b1cd31f7',
                  number: '+8616388942203',
                  parseCount: 0,
                  serviceCode: '106000078673950',
                  status: 'DELIVERED',
                  success: true,
                  type: 'TEXT',
                },
              ],
              total: 100,
            },
          })
        }, 500)
      })
      if (+code === 200) {
        return {
          data: data.list,
          total: +data.total,
        }
      }

      return {
        data: [],
        total: 0,
      }
    },
    handleSelectionChange(arr) {
      this.selectedArr = arr
    },
    async handleDelete() {
      this.$confirm(
        '选定的条目及条目相关的数据将被删除且不可恢复，您是否确定删除？',
        '删除',
        {
          iconClass: 'el-icon-warning-outline warning',
          center: true,
          closeOnClickModal: false,
        }
      )
    },

    handleShowAddEdit(item) {
      this.selectedRow = item || {}
      this.isAddEdit = true
      this.showAddEdit = true
    },
    handleShowImport() {
      this.showImport = true
    },
  },
}
</script>
<style lang="scss" scoped></style>
